/* eslint-disable no-unused-vars */

/**
 * 英文段位昵称转中文
 * @param {tier}
 */
export const englishToChinese = (tier: string) => {
  switch (tier) {
    case 'CHALLENGER':
      return '王者'
    case 'GRANDMASTER':
      return '宗师'
    case 'MASTER':
      return '大师'
    case 'DIAMOND':
      return '钻石'
    case 'EMERALD':
      return '翡翠'
    case 'PLATINUM':
      return '铂金'
    case 'GOLD':
      return '黄金'
    case 'SILVER':
      return '白银'
    case 'BRONZE':
      return '青铜'
    case 'IRON':
      return '黑铁'
    default:
      return '未定级'
  }
}

/**
 *  处理段位数据
 * @param {divsion}
 */
export const dealDivsion = (divsion: string) => {
  return divsion === 'NA' ? '' : divsion
}

interface Hero {
  id: number;
  player: string;
  stats: string;
  spellList: Array<number>;
}

interface PlayerData {
  championId: number;
  player: string;
  stats: string;
  spell1Id: number;
  spell2Id: number;
}
/**
 * 添加 player、status 到单局表详细信息对象
 * @param heroList 
 * @param playerData 
 */
export const UPDATE_CURRENT_PLAYER_KD = async (heroList: Array<Hero>, playerData: Array<PlayerData>): Promise<void> => {
  for (let i = 0; i < heroList.length; i++) {
    for (let j = 0; j < playerData.length; j++) {
      if (heroList[i].id === playerData[j].championId) {
        heroList[i].player = playerData[j].player
        heroList[i].stats = playerData[j].stats
        heroList[i].spellList = [playerData[j].spell1Id, playerData[j].spell2Id]
        break
      } else {
        heroList[i].player = 'NOT DATA'
        heroList[i].stats = 'NOT DATA'
        heroList[i].spellList = [0, 0]
      }
    }
  }
}

/**
   * 匹配数据过滤加入player对象便于找到召唤师名称
   * @param team_one_list 
   * @param team_two_list 
   * @param playerTeamOneData 
   * @param playerTeamTwoData 
   */
export const TEAM_FILTER_DATA = async (
  team_one_list: Array<object>,
  team_two_list: Array<object>,
  playerTeamOneData: Array<object>,
  playerTeamTwoData: Array<object>
) => {
  team_one_list.map((item: any) => {
    const playerData:any = playerTeamOneData.find((data: any) => data[0].participantId === item.participantId) || [];
    item.player = playerData[0].player
    item.spellList = [item.spell1Id, item.spell2Id]
  })
  team_two_list.map((item: any) => {
    const playerData: any = playerTeamTwoData.find((data: any) => data[0].participantId === item.participantId) || [];
    item.player = playerData[0].player
    item.spellList = [item.spell1Id, item.spell2Id]
  })
}

/**
 * 根据championId获取英雄名称
 * @param {championId}
 */
export const FILTER_HERO_NAME = (id: number, list: any): object => {
  let object = {}
  for (let i = 0; i < list.hero.length; i++) {
    if (list.hero[i].heroId == id) {
      return {
        ...object,
        id: id,
        name: list.hero[i].name + ' ' + list.hero[i].title,
        pic: `https://game.gtimg.cn/images/lol/act/img/champion/${list.hero[i].alias}.png`
      }
    }
  }
  return {}
}

/**
 * 根据 participantId 筛选出召唤师名称
 * @param {participantId}
 */
export const FILTER_NAME = (playerList: any): object => {
  for (let i = 0; i < playerList.participants.length; i++) {
    for (let j = 0; j < playerList.participantIdentities.length; j++) {
      if (playerList.participantIdentities[j].participantId === playerList.participants[i].participantId) {
        return {
          playerName: playerList.participants[i].player.summonerName
        }
      }
    }
  }
  return {}
}

/**
 *  判断localStorage是否存在某个值
 * @param {key}
 * @param {value}
 */
export const isStoreageHas = (key: string, value: string) => {
  const storeageJson = JSON.parse(String(localStorage.getItem(key)))
  if (storeageJson === null) {
    return false
  }
  if (value !== 'null' && storeageJson[value] === undefined) {
    return false
  }
  return true
}

/**
 * 通过召唤师技能id获取召唤师图片地址
 * @param {spellId}
 */
export const getspellImgUrl = (spellId: number) => {
  switch (spellId) {
    case 4:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/Summoner_flash.png'
    case 14:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/SummonerIgnite.png'
    case 11:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/Summoner_smite.png'
    case 6:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/Summoner_haste.png'
    case 12:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/Summoner_teleport.png'
    case 21:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/SummonerBarrier.png'
    case 3:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/Summoner_exhaust.png'
    case 1:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/Summoner_boost.png'
    case 7:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/Summoner_heal.png'
    case 32:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/Summoner_Mark.png'
    case 2201:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/Summoner_teleport.png'
    case 2202:
      return 'https://game.gtimg.cn/images/lol/act/img/spell/Summoner_flash.png'
  }
  return 'https://game.gtimg.cn/images/lol/act/img/spell/SummonerMana.png'
}

/**
 * 通过装备id获取图片地址
 * @param {item}
 */
export const GET_EQUIP_IMG = (item1: number, item2: number, item3: number, item4: number, item5: number, item6: number) => {
  const picList = [item1, item2, item3, item4, item5, item6]
  const pic = picList.map((item: number) => {
    if (item == 0) {
      return new URL("https://img0.baidu.com/it/u=2058135995,492936419&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1705251600&t=2d818a687793965556b7105c7da7f82f", import.meta.url).href;
    } else {
      return `https://game.gtimg.cn/images/lol/act/img/item/${item}.png`;
    }
  })
  return pic
};

/**
 * 用于存储当前对局信息
 * @params res.data.participantIdentities res.data.participants
 */
export const FILTERCURRENTDATA = async (p1: Array<object>, p2: Array<object>): Promise<void> => {
  let info_data: any = {
    playerInfo: [],
    statusInfo: []
  }
  p1.map((item: any) => info_data.playerInfo.push(item))
  p2.map((item: any) => info_data.statusInfo.push(item))
  return new Promise((resolve, reject) => {
    resolve(info_data)
  })
}

/**
 * 判断玩家位置
 * @param {lane}
 */
export const querySummonerPosition = (lane: string) => {
  switch (lane) {
    case 'MIDDLE':
      return '中单'
    case 'JUNGLE':
      return '打野'
    case 'BOTTOM':
      return '下路'
    case 'TOP':
      return '上单'
    case 'NONE':
      return '未知'
  }
}

/**
 * 获取位置序号, 方便排序
 * @param {selectedPosition}
 */
export const getPosition = (selectedPosition: string) => {
  switch (selectedPosition) {
    case 'BOTTOM':
      return 4
    case 'JUNGLE':
      return 2
    case 'TOP':
      return 1
    case 'MIDDLE':
      return 3
    case 'UTILITY':
      return 5
    case 'NONE':
      return 0
  }
}
